﻿using UnityEngine;
/// <summary>
/// 武器父类
/// </summary>
public abstract class BaseWeapon : MonoBehaviour
{
    public abstract string Name { get; }
    protected Animator animator; 
    public float interval; //攻击间隔时间
    private float time;    //计时参数
    protected Vector3 dir; //方向
    /// <summary>
    /// 外部调用的攻击方法
    /// </summary>
    /// <param name="dir"></param>
    public virtual void OnAttack(Vector3 dir)
    {
        if(CheckInterval())
        {
            this.dir = dir;
            Attack();
        }
    }
    /// <summary>
    /// 实际的攻击方法
    /// </summary>
    protected abstract void Attack();
    public bool CheckInterval()
    {
        time += Time.deltaTime;
        if (time >= interval)
        {
            time -= interval;
            return true;
        }
        return false;
    }
    protected virtual void Start()
    {
        animator = GetComponent<Animator>();
        time = 0;
    }
}
